﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KZ400B
{
	public partial class Axle
	{
        public enum RunType
        {
            Once = 0,
            Consequent = 10
        }

        TargetParameters m_targetParameters;

        public TargetParameters TargetParametersSetting
        {
            get { if (m_targetParameters == null) { m_targetParameters = new TargetParameters(); } return m_targetParameters; }
            //set { m_targetParameters = value; }
        }
        public class TargetParameters
        {
            public TargetParameters()
            {
                m_rslk = new object();
                m_rAPMlk = new object();
                m_Dir = null;
                m_Period = 0;
                m_TotalStep = 0;
                m_RunType = Axle.RunType.Once;
                m_needRun = false;
            }

            private Axle.Direction m_Dir;

            public Axle.Direction Direction
            {
                get { return m_Dir; }
                internal set { m_Dir = value; }
            }
            private double m_Period;

            public double Period
            {
                get { return m_Period; }
                internal set { m_Period = value; }
            }

            private double m_TotalStep;

            public double TotalStep
            {
                get { return m_TotalStep; }
                internal set { m_TotalStep = value; }
            }

            private object m_rAPMlk;
            private object m_rslk;
            private RunType m_RunType;

            public RunType RunType
            {
                get { return m_RunType; }
                internal set { m_RunType = value; }
            }

            private bool m_needRun;

            public bool NeedRun
            {
                get { return m_needRun; }
                internal set { m_needRun = value; }
            }

            public void Setting(            
            Axle.Direction dir
            , double period
            , double totalStep
                )
            {
                m_Dir = dir;
                m_Period = period;
                m_TotalStep = totalStep;
            }


            public void ResetPM()
            {
                m_Dir = Axle.Direction.ForwardDirection;
                m_Period = 0;
                m_TotalStep = 0;
            }

            public void SetRunState(RunType runType)
            {
                SetRunState(runType, true);
            }

            public void SetRunState(RunType runType, bool needRun)
            {
                lock (m_rslk)
                {
                    m_RunType = runType;
                    if (runType == Axle.RunType.Once)
                    {
                        m_needRun = false;
                    }
                    else
                    {
                        m_needRun = needRun;
                    }
                }
            }

            public void ResetRunState()
            {
                lock (m_rslk)
                {
                    m_RunType = Axle.RunType.Once;
                    m_needRun = false;
                }
            }

            private bool m_RunAfterPMSetting;

            public bool RunAfterPMSetting
            {
                get { lock (m_rAPMlk) { return m_RunAfterPMSetting; } }
                set { lock (m_rAPMlk) { m_RunAfterPMSetting = value; } }
            }

            private int m_Acceleration;

            public int Acceleration
            {
                get { return m_Acceleration; }
                set { m_Acceleration = value; }
            }
        }
	}
}
